package com.knowledge.handler.init;

import com.knowledge.service.SysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * @author zzz
 * @title: InitListener
 * @projectName knowledge-api
 * @description: TODO
 * @date 2022-03-05 18:44
 */
@Slf4j
@Component
public class InitListener implements ApplicationListener<ContextRefreshedEvent> {

    @Autowired
    private SysUserService sysUserService;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        if (event.getApplicationContext().getParent() == null){
            log.info("初始化数据--start---");
            sysUserService.initEffectiveUser();
            log.info("初始化数据--end---");
        }
    }
}
